package com.laker.autotest.api.core.auth;

import java.util.concurrent.atomic.AtomicReference;

/**
 * Bearer Token Provider，适用于 OAuth2 等场景
 */
public class BearerAuthTokenProvider implements AuthTokenProvider {
    protected final AtomicReference<String> token = new AtomicReference<>(null);

    public BearerAuthTokenProvider(String initialToken) {
        this.token.set(initialToken);
    }

    /**
     * 设置/刷新 token，供子类调用
     */
    public void setToken(String newToken) {
        this.token.set(newToken);
    }

    @Override
    public String getAuthHeader() {
        String t = token.get();
        return t == null ? null : ("Bearer " + t);
    }
}
